﻿using AutoMapper;
using B.S.Sterilizationcenter.Domain.wjl;
using B.S.Sterilizationcenter.ErrorCode;
using B.S.Sterilizationcenter.Writer.API.Appliaction.Commends.WJL;
using MediatR;
using SqlSugar;

namespace B.S.Sterilizationcenter.Writer.API.Appliaction.CommandHandlers.WJL
{
    public class UpdateAuditCleanwatchCommandHanders:IRequestHandler<UpdateAuditCleanwatchCommands,ApiResult<int>>
    {
        private readonly ISqlSugarClient db;
        private readonly IMapper mapper;

        public UpdateAuditCleanwatchCommandHanders(ISqlSugarClient db, IMapper mapper)
        {
            this.db = db;
            this.mapper = mapper;
        }

        /// <summary>
        /// 审核清洗信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<ApiResult<int>> Handle(UpdateAuditCleanwatchCommands request, CancellationToken cancellationToken)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {

                var list = db.Updateable<Cleanwatch>().SetColumns(x => x.Status == 3).Where(x => x.CleaningId == request.CleaningId).ExecuteCommand();

                result.Code = list > 0 ? ApiEnums.修改成功 : ApiEnums.修改失败;
                result.Msg = list > 0 ? "审核成功" : "未找到匹配记录";
            }
            catch (Exception ex)
            {
                result.Code = ApiEnums.修改失败;
                result.Msg = $"更新失败：{ex.Message}";
            }

            return result;
        }
    }
}
